package cn.kk.api.feign;

import cn.kk.api.feign.config.FeignClientInterceptor;
import cn.kk.constant.RedisKeyConstant;
import cn.kk.model.user.entity.UserInfoEntity;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;

/**
 * @Author: kk
 * @Date: 2023/2/19  18:49
 * @Version 1.0
 */
@FeignClient(value = "user-service", path = "/user/api/info", configuration = FeignClientInterceptor.class)
public interface UserInfoClient {

    /**
     * 验重
     * @return 是否重复
     */
    @GetMapping("/checkRepeat")
    boolean checkRepeat(@RequestParam(value = "phone", required = false) String phone,
                        @RequestParam(value = "email", required = false) String email);

    /**
     * 新增用户
     * @param userInfo 用户信息
     * @return 执行结果
     */
    @PostMapping("/save")
    boolean save(@RequestBody UserInfoEntity userInfo);

    /**
     * 根据手机/邮箱查询用户
     * @param account 账号
     * @return 用户信息
     */
    @GetMapping("/search")
    UserInfoEntity search(@RequestParam(value = "account") String account);

    /**
     * 获取当前访问用户
     * @return 获取当前访问用户
     */
    @GetMapping("/currentUser")
    UserInfoEntity currentUser();

    /**
     * 根据id查询用户
     * @param id 用户id
     * @return 用户信息
     */
    @GetMapping("/getUser/{id}")
    @Cacheable(value = RedisKeyConstant.USER_INFO_KEY, key = "#id", unless = "#result == null")
    UserInfoEntity getUser(@PathVariable("id") Serializable id);

}
